package com.lukk.service.impl;

import java.util.List;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.lukk.dao.PotentialWorkerDAO;
import com.lukk.pojo.PotentialWorker;
import com.lukk.service.IPotentialWorkerService;

/**
 * 
 * PotentialWorkerServiceImpl 上午10:25:32
 * 
 * Copyright zhaocj Inc. All rights reserved.
 * Love ME Like Justin Bieber.
 */
@Service("potentialWorkerService")
public class PotentialWorkerServiceImpl implements IPotentialWorkerService {
	private static Logger logger = LogManager.getLogger(PotentialWorkerServiceImpl.class.getName());
	@Autowired
	private PotentialWorkerDAO potentialWorkerDAO;

	public PotentialWorkerDAO getPotentialWorkerDAO() {
		return potentialWorkerDAO;
	}

	public void setPotentialWorkerDAO(PotentialWorkerDAO potentialWorkerDAO) {
		this.potentialWorkerDAO = potentialWorkerDAO;
	}

	public Integer insertPotentialWorker(PotentialWorker potentialWorker) {
		return potentialWorkerDAO.insertPotentialWorker(potentialWorker);
	}

	@Override
	public boolean isCodeAlreadyUsed(PotentialWorker potentialWorker) {
		if (potentialWorkerDAO.isCodePhoneAlreadyUsed(potentialWorker).isEmpty()) {
			logger.debug("这个账号还没有使用===================");
			return false;
		} else {
			logger.debug("这个账号已经使用====================");
			return true;
		}
	}

	@Override
	public List<PotentialWorker> selectByBean(PotentialWorker potentialWorker) {
		return potentialWorkerDAO.selectByBean(potentialWorker);
	}

	@Override
	public boolean modifyByBean(PotentialWorker potentialWorker) {
		potentialWorkerDAO.modifyByBean(potentialWorker);
		return true;
	}

	@Override
	public boolean deleteByPrimaryKey(String drops) {
		String[] splits = drops.split(",");
		Integer[] dropsArry = new Integer[splits.length];
		for (int i = 0; i < splits.length; i++) {
			dropsArry[i] = Integer.valueOf(splits[i]);
		}
		potentialWorkerDAO.deleteByPrimaryKey(dropsArry);
		return true;
	}

	@Override
	public Integer deleteByPhone(String phone) {
		Integer internalWokerID = potentialWorkerDAO.selectIntenalWorkerIDByPhone(phone);
		potentialWorkerDAO.deleteByPhone(phone);
		return internalWokerID;
	}

	@Override
	public PotentialWorker selectByPrimaryKey(PotentialWorker potentialWorker) {
		return potentialWorkerDAO.selectByPrimaryKey(potentialWorker);
	}

}
